package com.lww.feature.test.optional;

import org.junit.Test;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.Optional;

/**
 * User: yian
 * Date: 2017/5/2
 */
public class test {
    @Test
    public void testof() {
        Optional<BigDecimal> zero = Optional.of(BigDecimal.ZERO);
        System.out.println(zero.get());
        try {

            Optional<BigDecimal> optional = Optional.of(null);
            System.out.println(optional.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {

            Optional<Object> o = Optional.ofNullable(null);
            System.out.println("============");
            System.out.println(o.orElse(BigDecimal.ZERO));
        } catch (Exception e) {
            e.printStackTrace();
        }
        try {

            Optional<Object> o = Optional.ofNullable(null);
            System.out.println("=========+++++++++++");
            o.orElse(null);
            System.out.println(o.orElse(null));
        } catch (Exception e) {
            e.printStackTrace();
        }



    }

    @Test
    public void nullMap() {
        BigDecimal bd = null;
        String s = Optional.ofNullable(bd).map(BigDecimal::toString).orElse("---");
        System.out.println(s);
    }
}
